{% load humanize %}
{% load task_tags %}
{% load tagging_tags %}

<div class="tasks">
  <table class="task">
    <tr>
      <th>Title</th>
      <th>Related to</th>
      <th>Status</th>
      <th>Owner</th>
      <th>Start Date</th>
      <th>Estimate</th>
      <th>Due Date</th>
      <th>Completed Date</th>
      <th>Tags</th>
      <td colspan="2"/>
    </tr>
    {% for task in task_list %}
    <tr>
      <td><a href="{% url task_detail object_id=task.id %}">{{ task.title }}</a></td>
      <td>
        {% if task.parent %}
          <a href="{% url task_detail object_id=task.parent.id %}">{{ task.parent }} (task)</a>
        {% endif %}

        {% for deliverable in task.deliverable_set.all %}
	  <a href="{% url deliverable_detail object_id=deliverable.id %}">{{ deliverable }} (deliverable)</a>
        {% endfor %}  

        {% for objective in task.objective_set.all %}
          <a href="{% url objective_detail object_id=objective.id %}">{{ objective }} (Objective)</a>
        {% endfor %}
      </td>
      <td>{% task_status task %}</td>
      <td>{{ task.lead }}</td>
      <td>{{ task.start_date|naturalday }}</td>
      <td>{{ task.estimate }}</td>
      <td>{{ task.target_date|naturalday }}</td>
      <td>{{ task.completed_date|naturalday }}</td>
      <td>
        {% tags_for_object task as tags %} 
        {% for tag in tags %}
          <a href="{% url project_tagged_task tag_name=tag.name %}">{{ tag.name }}</a>
        {% endfor %}
      </td>

      <td>
	{% if task.completed_date %}
	<form action="{% url task_set_complete task_id=task.id %}" method="post">
	  <input type="hidden" name="status" value="incomplete" />
	  <input type="submit" value="Incomplete" />
	</form>
	{% endif %}
      {% if not task.completed_date %}
	<form action="{% url task_set_complete task_id=task.id %}" method="post">
	  <input type="hidden" name="status" value="complete" />
	  <input type="submit" value="Complete" />
	</form>
      {% endif %}
      </td>
      <td><a href="{% url task_edit task_id=task.id %}">Edit</td>
    </tr>
    {% endfor %}
  </table>
</div>
